package com.esunrising.esungsc.controller;

import com.esunrising.esungsc.dto.Result;
import com.esunrising.esungsc.dto.SysApiUrlReq;
import com.esunrising.esungsc.dto.SysConfigReq;
import com.esunrising.esungsc.entity.SysApiUrl;
import com.esunrising.esungsc.entity.SysConfig;
import com.esunrising.esungsc.service.SysApiUrlService;
import com.esunrising.esungsc.service.SysConfigService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/sys/api/v1/sysApiUrl")
@Api(value = "/sys/api/v1/sysApiUrl", tags = {"系统配置接口处理模块"})
@Slf4j
public class SysApiUrlController {


    @Resource
    private SysApiUrlService sysApiUrlService;

    @GetMapping("/{uuid}")
    Result<SysApiUrl> getById(@PathVariable String uuid) {
        return Result.ok(sysApiUrlService.findById(uuid));
    }

    @PostMapping("/save")
    Result<SysApiUrl> save(@RequestBody SysApiUrlReq sysApiUrlReq) {
        SysApiUrl sysApiUrl = new SysApiUrl();
        sysApiUrl.setConfigKey(sysApiUrlReq.getConfigKey());
        sysApiUrl.setConfigName(sysApiUrlReq.getConfigName());
        sysApiUrl.setConfigValue(sysApiUrlReq.getConfigValue());
        sysApiUrlService.save(sysApiUrl);
        return Result.ok(sysApiUrl);
    }

    @GetMapping("/getConfigValueByConfigKey")
    Result<String> getConfigValueByConfigKey(@RequestParam String configKey) {
        return Result.ok(sysApiUrlService.findConfigValueByConfigKey(configKey));
    }

    @GetMapping("/getSysConfigByConfigKey")
    Result<SysApiUrl> getSysConfigByConfigKey(@RequestParam String configKey) {
        return Result.ok(sysApiUrlService.findByConfigKey(configKey));
    }



}